<?php
namespace Admin\Model;

class NewsModel extends  \Think\Model{
    
    protected  $_auto=array(
        
        array('ctime','time',1,'function'),
        array('utime','time',2,'function'),
    );
    
    protected  $_validate=array(
    
        array('title','require','标题不能为空',1,'regex',1),
        array('title','5,20','标题必须为5-20个字符',1,'length',1),
        array('title','','标题不能重复',1,'unique',3),
    );
    
    function addNews(){
        if($this->create()){
            
            $result=$this->add();
            
            if($result!==false){
                //$this->redirect('index');
                
                return  $result;
            }else {
                return '新增失败';
            }
        }else{
            return $this->getError();
        }
    }
    
    function editNews(){
        if($this->create()){
        
            $result=$this->where(array('id'=>I('post.id')))->save();
        
            if($result!==false){
                //$this->redirect('index');
        
                return  $result;
            }else {
                return '修改失败';
            }
        }else{
            return $this->getError();
        }
    }
    
}